package com.jugheadzhou.emrpoc.controller;

import com.alibaba.fastjson.JSON;
import com.jugheadzhou.emrpoc.common.Result;
import com.jugheadzhou.emrpoc.model.MedicalRecordType;
import com.jugheadzhou.emrpoc.service.MedicalRecordTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author jugheadzhou
 * @date 2021-10-24
 */
@Slf4j
@RestController
@RequestMapping("/mrType")
public class MedicalRecordTypeController {
    @Resource
    private MedicalRecordTypeService medicalRecordTypeService;

    /**
     * 病历类型查看列表
     *
     * @return
     */
    @GetMapping("list")
    public Result<?> list() {
        return Result.success(medicalRecordTypeService.list());
    }

    /**
     * 病历类型保存
     *
     * @param medicalRecordType 病历类型对象
     * @return
     */
    @PostMapping("save")
    public Result<?> save(@RequestBody MedicalRecordType medicalRecordType) {
        log.info("病历模板保存开始：{}", JSON.toJSONString(medicalRecordType));
        return Result.success(medicalRecordTypeService.save(medicalRecordType));
    }

    /**
     * 病历类型删除
     *
     * @param id 病历类型主键ID
     * @return
     */
    @DeleteMapping("delete")
    public Result<?> delete(String id) {
        log.info("病历类型删除开始：{}", id);
        return Result.success(medicalRecordTypeService.delete(id));
    }
}
